﻿using Library.OrmEnterpriseEntity.TableInfo;
using System.Text;

namespace Library.OrmEnterpriseEntity {
	public sealed class SelectStatement {
		private readonly DbColumnView[] _cols;
		internal bool IsCount;
		internal SelectStatement(params DbColumnView[] selectCols) {
			_cols = selectCols;
		}
		internal SelectStatement(bool countTrue) {
			IsCount = countTrue;
		}


		public SelectQueryStatement From(GlobalEntityView table) {
			//return From(table, null);
			return From(table, null, null);
		}
		public SelectQueryStatement From(GlobalEntityView table, ISelectOption selectOption) {
			return From(table, null, selectOption);
		}
		public SelectQueryStatement From(GlobalEntityView table, StringBuilder sqlTracking, ISelectOption selectOption) {
			var q = new SelectQueryStatement(table, sqlTracking);
			q.SelectOption = selectOption;
			if (_cols.Length > 0) {
				q.SelectCols.AddRange(_cols);
			} else {
				q.SelectCols.AddRange(table.Columns);
			}

			return q;
		}

		public SelectQueryStatement From(GlobalEntityView table, StringBuilder sqlTracking) {
			return From(table, sqlTracking, null);
		}
	}
}
